/*
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "cardsender_client_test.h"
#include <iostream>
#include <string>
#include <gtest/gtest.h>
#include "hilog_wrapper.h"
#include "cardsender_srv_client.h"
#include "test_utils.h"

using namespace testing::ext;
using namespace SwanLink::Finance;
using namespace OHOS;
using namespace std;

namespace {
bool g_isMock = false;
}

void CardsenderClientTest::SetUpTestCase(void)
{
    g_isMock = TestUtils::IsMock();
    GTEST_LOG_(INFO) << " g_isMock: " << g_isMock;
}

void CardsenderClientTest::TearDownTestCase(void)
{
    g_isMock = false;
    TestUtils::ResetOnline();
}

void CardsenderClientTest::SetUp(void)
{
}

void CardsenderClientTest::TearDown(void)
{
}

namespace {
/**
 * @tc.name: CardsenderClient001
 * @tc.desc: Test Cardsender interface Open
 * @tc.type: FUNC
 */
HWTEST_F(CardsenderClientTest, CardsenderClient001, TestSize.Level1)
{
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient001 start.");
    auto& client = CardsenderSrvClient::GetInstance();
    if (g_isMock) {
        std = {};
        Transport trans = {};
        auto ret = client.Open(std, trans);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient001 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        std = {};
        Transport trans = {};
        auto ret = client.Open(std, trans);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient001 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient001 end.");
}
/**
 * @tc.name: CardsenderClient002
 * @tc.desc: Test Cardsender interface Close
 * @tc.type: FUNC
 */
HWTEST_F(CardsenderClientTest, CardsenderClient002, TestSize.Level1)
{
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient002 start.");
    auto& client = CardsenderSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;
        auto ret = client.Close(handle);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient002 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;
        auto ret = client.Close(handle);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient002 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient002 end.");
}
/**
 * @tc.name: CardsenderClient003
 * @tc.desc: Test Cardsender interface Reset
 * @tc.type: FUNC
 */
HWTEST_F(CardsenderClientTest, CardsenderClient003, TestSize.Level1)
{
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient003 start.");
    auto& client = CardsenderSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;

        auto ret = client.Reset(handle);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient003 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;

        auto ret = client.Reset(handle);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient003 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient003 end.");
}
/**
 * @tc.name: CardsenderClient004
 * @tc.desc: Test Cardsender interface DispenseCard
 * @tc.type: FUNC
 */
HWTEST_F(CardsenderClientTest, CardsenderClient004, TestSize.Level1)
{
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient004 start.");
    auto& client = CardsenderSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;

        auto ret = client.DispenseCard(handle);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient004 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;

        auto ret = client.DispenseCard(handle);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient004 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient004 end.");
}
/**
 * @tc.name: CardsenderClient005
 * @tc.desc: Test Cardsender interface GetSupportAccess
 * @tc.type: FUNC
 */
HWTEST_F(CardsenderClientTest, CardsenderClient005, TestSize.Level1)
{
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient005 start.");
    auto& client = CardsenderSrvClient::GetInstance();
    if (g_isMock) {
        auto ret = client.GetSupportAccess();
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient005 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        auto ret = client.GetSupportAccess();
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient005 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient005 end.");
}
/**
 * @tc.name: CardsenderClient006
 * @tc.desc: Test Cardsender interface QueryStatus
 * @tc.type: FUNC
 */
HWTEST_F(CardsenderClientTest, CardsenderClient006, TestSize.Level1)
{
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient006 start.");
    auto& client = CardsenderSrvClient::GetInstance();
    if (g_isMock) {
        int handle = -1;
        unsigned char pSuppBinStat[128] = { 0 };
        unsigned char pRetainBinStat[128] = { 0 };

        auto ret = client.QueryStatus(handle, pSuppBinStat, pRetainBinStat);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient006 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    } else {
        int handle = -1;
        unsigned char pSuppBinStat[128] = { 0 };
        unsigned char pRetainBinStat[128] = { 0 };

        auto ret = client.QueryStatus(handle, pSuppBinStat, pRetainBinStat);
        CARDSENDER_HILOGI(CARDSENDER_TEST, "CardsenderClientTest::ret=%{public}d", ret);
        GTEST_LOG_(INFO) << "CardsenderClient::CardsenderClient006 executing, ret = " << ret;
        ASSERT_EQ(ret == 0);
    }
    CARDSENDER_HILOGD(CARDSENDER_TEST, "CardsenderClient::CardsenderClient006 end.");
}
}